package com.guigu.servicebusiness.controller;


import com.guigu.common_util.pojo.utils.Result;
import com.guigu.servicebusiness.entity.TbAd;
import com.guigu.servicebusiness.service.ITbAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-07-09
 */
@RestController

@RequestMapping("/servicebusiness/tb-ad")
public class TbAdController {

    @Autowired
    private ITbAdService iTbAdService;

    @PostMapping("/ad/findPage.do")
    public Result page(@RequestBody(required = false) Map<String,Object> sercherMap, Integer page, Integer size){
        return iTbAdService.findPage(sercherMap, page, size);
    }

    @GetMapping("/getByid")
    public Result getByid(Integer id){
        TbAd byId = iTbAdService.getById(id);
        if (byId!=null)
            return Result.ok().data("byId",byId);
        return Result.error();
    }

    @PostMapping("/ad/add.do")
    public Result add(@RequestBody TbAd tbAd){
        iTbAdService.insert(tbAd);
        return Result.ok();
    }

    @PostMapping("/ad/update.do")
    public Result update(@RequestBody TbAd tbAd){
        iTbAdService.ByIdupdate(tbAd);
        return Result.ok();
    }


    @GetMapping("/ad/delete.do")
    public Result delete(Integer id){
        iTbAdService.ByIdremove(id);
        return Result.ok();

    }

    @PostMapping("/ad/deletlist")
    public Result deletelist(@RequestBody List<TbAd> list){
        iTbAdService.deletelist(list);
        return Result.ok();
    }

    // 根据位置查询广告列表
    @GetMapping("/findByPosition")
    public List<TbAd> findByPosition(String position) {
        return iTbAdService.findByPosition(position);
    }


}

